﻿#region namespace

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

#endregion

namespace Janus.Cores.Configuration
{
    /// <summary>
    /// 客户端配置节
    /// </summary>
    public class ClientSection : System.Configuration.ConfigurationSection
    {
        internal const string SECTION_NAME = "clients";

        [ConfigurationProperty("client", Options = ConfigurationPropertyOptions.None)]
        public ClientElementCollection Clients {
            get { return (ClientElementCollection)base["client"]; }

        }

    }
    /// <summary>
    /// 
    /// </summary>
    public class ClientElementCollection : ConfigurationElementCollection
    {
        /// <summary>
        /// 
        /// </summary>
        public ClientElementCollection()
        {
            base.AddElementName = "client";
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected override ConfigurationElement CreateNewElement()
        {
            return new ClientElement();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        protected override object GetElementKey(ConfigurationElement element)
        {
            var el = (element as ClientElement);
            return string.Format("{0}.{1}",el.Assembly,el.Type);
        }
    }
    /// <summary>
    /// 
    /// </summary>
    public class ClientElement : ConfigurationElement
    {
        /// <summary>
        /// 
        /// </summary>
        [ConfigurationProperty("address", IsRequired = true)]
        public string Address
        {
            get { return (string)base["address"]; }
            set { base["address"] = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        [ConfigurationProperty("assembly", IsRequired = true)]
        public string Assembly
        {
            get { return (string)base["assembly"]; }
            set { base["assembly"] = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        [ConfigurationProperty("type", IsRequired = false)]
        public string Type
        {
            get { return (string)base["type"]; }
            set { base["type"] = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        [ConfigurationProperty("isBidirectional", IsRequired = false, DefaultValue = true)]
        public bool IsBidirectional
        {
            get { return (bool)base["isBidirectional"]; }
            set { base["isBidirectional"] = value; }
        }
    }
}
